<?php

namespace Common\Model;
use think\Model;

class UserOrderCartModel extends BaseModel{

	//追加属性
    public $append = [
        'add_time_text',
        'price',
        'amount',
        'goods_img',
	];
  
    /**
     * 单价数据调整
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getPriceAttr($value, $data){
        $price = floatval($data['price']);
		return $price;
    }
     /**
     * 金额
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getAmountAttr($value, $data){
        $amount = 0;
        $price = 0;
        if($data['discount']>0){
            $price = bcmul($data['price'],$data['discount'],2);
        }else{
            $price = $data['price'];
        }
        $amount = bcmul($price,$data['number'],2);
		return floatval($amount);
    }
    /**
     * 商品图片
     * @param $value
     * @param $data
     * @return mixed
    */
    public function getGoodsImgAttr($value, $data){
        $goods_img = '';
        $g_model = D('UserGoods');
        $goods_img = $g_model->where(['uid'=>UID,'id'=>$data['goods_id']])->getField('goods_img');
		return $goods_img?:'';
    }
}